package com.cskt.controller;

import com.cskt.entity.Student;
import com.cskt.service.StudentService;
import com.cskt.util.Pager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.HashMap;
import java.util.List;

/**
 * Created by bb on 2018/3/12.
 * 学生类的控制器
 */
@Controller
@RequestMapping("user")
public class StudentController {
    @Autowired
    private StudentService studentService;

    @RequestMapping("/toShow.ev")
    public String toShow(ModelMap modelMap){
       List<Student> list= studentService.getAllStudent();
       modelMap.addAttribute("list",list);
       return "show";
    }
    @RequestMapping("/delete.ev")
    public String selectDete(Integer sid){
        int count=studentService.studentDelet(sid);

        if(count<1){
            System.out.print(count+"+++++++++++++++++++");
            return "redirect:toShow.ev";

        }else{
            System.out.print(count+"-----------------------");
            return "redirect:toShow.ev?user=ok";

        }
    }
    @RequestMapping("/studentIdFind.ev")
    public String studentId(Integer sid,ModelMap modelMap){
        Student list= studentService.studentId(sid);
        System.out.print(list.getStuNo());
        modelMap.addAttribute("list",list);
        return "update";
    }
    @RequestMapping("/update.ev")
    public String updateStudent(Student student){
        System.out.print(student.getSid()+"------------------");
        System.out.print(student.getStuName()+"------------------");
        int count=studentService.updateStudent(student);
        return "redirect:toShow.ev";
    }
    @RequestMapping("/addStudent.ev")
    public String addStudnets(Student student){
        int count=studentService.addStudnet(student);
        return  "redirect:toShow.ev";
    }
    @RequestMapping("/addStudents.ev")
    public String addStudnets(){
        return "addStudent";
    }
    @RequestMapping("byPager.ev")
    public String byPager(Pager pager,ModelMap modelMap){
        List<Student> list=studentService.getByPagers(pager);
        modelMap.addAttribute("list",list);
        modelMap.addAttribute("pager",pager);
        return "show";
    }
}
